home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / culldir.c < prev    next >
C/C++ Source or Header  |  1997-07-27  |  2KB  |  77 lines

  1. /* this utility will make two passes over the current directory and
  2. ** the filedir.txt. The first pass will remove missing files from
  3. ** the entries, the second will add new ones.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "sysdep.h"
  9.  
  10. int parsename(char *, char *);
  11. int  main(int,char **);
  12. int  main(int argc,char **argv)
  13.   {
  14.   FILE *fopen(), *fd, *fo;
  15.   char line[8000], *fgets(), name[20];
  16.   fprintf(stderr,"Citadel CULLDIR %s\n%s", VERSION_NAME, COPYRIGHT );
  17.   if ((fd = fopen("filedir.txt", "r")) == NULL)
  18.     {
  19.     printf("Couldn't find a filedir.txt.");
  20.     return 10;
  21.     }
  22.   else
  23.     {
  24.     if ((fo = fopen("$tmp0000.dat", "w")) == NULL)
  25.       {
  26.       printf("Couldn't create temporary file");
  27.       return 10;
  28.       }
  29.     else
  30.       {
  31.       printf("...processing data\n");
  32.       while (fgets(line, 7998, fd) != NULL)
  33.         {
  34.         if (parsename(line, name))
  35.           {
  36.           if (access(name, 0) == 0)
  37.             {
  38.             fprintf(fo, "%s", line);
  39.  
  40.             }
  41.           else if (line[0] == ';') fprintf(fo, "%s", line);
  42.  
  43.           }
  44.         else if (line[0] == ';') fprintf(fo, "%s", line);
  45.  
  46.         }
  47.       fclose(fo);
  48.       }
  49.     fclose(fd);
  50.     unlink("filedir.txt");
  51.     rename("$tmp0000.dat", "filedir.txt");
  52.     }
  53.   return 0;
  54.   }
  55. parsename(src, target)
  56. char *src, *target;
  57.   {
  58.   char *strchr(), *space;
  59.   if ((space = strchr(src, ' ')) != NULL)
  60.     {
  61.     while (src != space)
  62.     *target++ = *src++;
  63.     *target = 0;
  64.     return 1;
  65.  
  66.     }
  67.   if (*src != ';')
  68.     {
  69.     strcpy(target, src);
  70.     if ((space = strchr(target, '\n')) != NULL) *space = 0;
  71.     return 1;
  72.  
  73.     }
  74.   return 0;
  75.  
  76.   }
  77.